package com.zy.spring3;

//演示转发和重定向

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/spring2")
public class SpringMVC_Test2
{

    @RequestMapping("welcome")
    public String welcome()
    {
        return "welcome";
    }

    @RequestMapping("index")
    public String index(Integer size)
    {
        System.out.println(size);
        //转发
        //return "forward:/spring2/welcome";
        //重定向
        return "redirect:/spring2/welcome";
    }

    @RequestMapping(value = "login",method= RequestMethod.POST)//只接受POST请求
    public String login(String username,@RequestParam("passworld") String pw)//@RequestParam("passworld")设置请求参数
    {
        System.out.println(username+"---"+pw);
        return "welcome";
    }

    @RequestMapping("list")
    public String List(@RequestParam(value = "user",defaultValue = "1") String user,String pw)//如果与value值不匹配，则打印默认值
    {
        System.out.println(user+"-----"+pw);
        return "list";
    }

    @RequestMapping("/list/{id}")
    public String list1(@PathVariable("id") Integer id)//路径变量
    {
        System.out.println(id);
        return "list";
    }

    @RequestMapping("cookie")
    public String cookie(@CookieValue("JSESSIONID") String cookieId)
    {
        System.out.println(cookieId);
        return "welcome";
    }
}
